<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="活动名称" prop="actiName">
      <el-input v-model="dataForm.actiName" placeholder="活动名称"></el-input>
    </el-form-item>
    <el-form-item label="活动主题" prop="actiTheme">
      <el-input v-model="dataForm.actiTheme" placeholder="活动主题"></el-input>
    </el-form-item>
    <el-form-item label="活动地点" prop="actiPlace">
      <el-input v-model="dataForm.actiPlace" placeholder="活动地点"></el-input>
    </el-form-item>
<!--    <el-form-item label="活动组织者" prop="actiOrigin">-->
<!--      <el-input v-model="dataForm.actiOrigin" placeholder="活动组织者"></el-input>-->
<!--    </el-form-item>-->
      <el-form-item label="活动组织者" prop="actiOrigin">
        <el-select v-model="dataForm.actiOrigin" placeholder="请选择">
          <el-option v-for="(item,i) in employeeModel" :label="item.employeeNameConcatId" :value="item.employeeId"></el-option>
        </el-select>
      </el-form-item>
    <el-form-item label="联系电话" prop="actiPhone">
      <el-input v-model="dataForm.actiPhone" placeholder="联系电话"></el-input>
    </el-form-item>
    <el-form-item label="参与该活动的会员" prop="actiMemberids">
      <el-input v-model="dataForm.actiMemberids" placeholder="参与该活动的会员"></el-input>
    </el-form-item>
      <el-form-item label="活动日期" prop="actiDate">
        <el-date-picker
          v-model="dataForm.actiDate"
          type="date"
          placeholder="选择日期"
          format="yyyy 年 MM 月 dd 日"
          value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="备注" prop="actiNote">
        <el-input v-model="dataForm.actiNote" placeholder="备注"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    created () {
      this.getEmployeeInfo()
    },
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          actiName: '',
          actiTheme: '',
          actiPlace: '',
          actiOrigin: '',
          actiPhone: '',
          actiMemberids: '',
          actiNote: '',
          actiDate: '',
          createTime: '',
          updateTime: ''
        },
        dataRule: {
          actiName: [
            { required: true, message: '活动名称不能为空', trigger: 'blur' }
          ],
          actiTheme: [
            { required: true, message: '活动主题不能为空', trigger: 'blur' }
          ],
          actiPlace: [
            { required: true, message: '活动地点不能为空', trigger: 'blur' }
          ],
          actiOrigin: [
            { required: true, message: '活动组织者不能为空', trigger: 'blur' }
          ],
          actiPhone: [
            { required: true, message: '联系电话不能为空', trigger: 'blur' }
          ],
          actiMemberids: [
            // { required: true, message: '参与该活动的会员不能为空', trigger: 'blur' }
          ],
          actiNote: [
          ],
          actiDate: [
            { required: true, message: '活动日期不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ]
        },
        employeeModel: {
          employeeId: '',
          employeeNameConcatId: ''
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/tb_bs_activity/bsactivity/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.actiName = data.bsActivity.actiName
                this.dataForm.actiTheme = data.bsActivity.actiTheme
                this.dataForm.actiPlace = data.bsActivity.actiPlace
                this.dataForm.actiOrigin = data.bsActivity.actiOrigin
                this.dataForm.actiPhone = data.bsActivity.actiPhone
                this.dataForm.actiMemberids = data.bsActivity.actiMemberids
                this.dataForm.actiNote = data.bsActivity.actiNote
                this.dataForm.actiDate = data.bsActivity.actiDate
                this.dataForm.createTime = data.bsActivity.createTime
                this.dataForm.updateTime = data.bsActivity.updateTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/tb_bs_activity/bsactivity/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'actiName': this.dataForm.actiName,
                'actiTheme': this.dataForm.actiTheme,
                'actiPlace': this.dataForm.actiPlace,
                'actiOrigin': this.dataForm.actiOrigin,
                'actiPhone': this.dataForm.actiPhone,
                'actiMemberids': this.dataForm.actiMemberids,
                'actiNote': this.dataForm.actiNote,
                'actiDate': this.dataForm.actiDate,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      },
      //获取员工信息下拉
      getEmployeeInfo () {
        this.$http({
          url: this.$http.adornUrl(`/tb_bs_protocol/bsprotocol/queryAllEmployee`),
          method: 'get'
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.employeeModel = data.date
          }
        })
      },
    }
  }
</script>
